﻿using System.Diagnostics;
using System.ServiceModel;
using System.ServiceProcess;

namespace RemoteWorker.Server
{
    public partial class RemoteWorkerServerService : ServiceBase
    {
        public RemoteWorkerServerService()
        {
            InitializeComponent();

//            if (!EventLog.SourceExists("RemoteWorkerServerLogSourse"))
//                EventLog.CreateEventSource("RemoteWorkerServerLogSourse", "RemoteWorkerServerLog");
//
//            eventLog.Source = "RemoteWorkerServerLogSourse";
//            eventLog.Log = "RemoteWorkerServerLog";
        }

        internal void Start(string[] args)
        {
            OnStart(args);
        }

        internal void ConsoleStop()
        {
            OnStop();
        }

        protected override void OnStart(string[] args)
        {
            _workerServer = new WorkerServer();
            _workerManager = new WorkerManager(_workerServer);

            _workerManagerHost = new ServiceHost(_workerManager);
            _workerServerHost = new ServiceHost(_workerServer);

            _workerManagerHost.Open();
            _workerServerHost.Open();
        }


        protected override void OnStop()
        {
            _workerManagerHost.Close();
            _workerServerHost.Close();
        }

        private WorkerServer _workerServer;
        private WorkerManager _workerManager;
        private ServiceHost _workerManagerHost;
        private ServiceHost _workerServerHost;
    }
}